<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>product</title>
    <script type="text/javascript" src="../frame/assets/js/lib/jquery.min.js"></script>
    <script src="https://apps.bdimg.com/libs/jquery/2.1.4/jquery.min.js"></script>
    <script src="../frame/layui/lay/modules/layer.js"></script>
    <link rel="stylesheet" href="../frame/layui/lay/modules/layer/default/layer.css">
    <link rel="stylesheet" href="../frame/layui/css/layui.css"  media="all">
    <link rel="stylesheet" href="../frame/assets/css/lib/bootstrap.min.css">
    <link rel="stylesheet" href="../frame/assets/css/lib/font-awesome.min.css">
    <link rel="stylesheet" href="../frame/assets/css/lib/themify-icons.css">
    <link rel="stylesheet" href="../frame/assets/css/lib/unix.css">
    <link rel="stylesheet" href="../frame/assets/css/style.css">
    <link rel="stylesheet" href="../frame/assets/css/lib/menubar/sidebar.css">
    <link rel="stylesheet" href="../frame/assets/css/lib/sweetalert/sweetalert.css">
</head>
<body>
<div class="content-wrap">
    <div class="main">
        <div class="container-fluid" >
            <!--欢迎栏-->
            <div class="row" >
                <div class="col-lg-8 p-r-0 title-margin-right">
                    <div class="page-header">
                        <div class="page-title" >
                            <h1>资产管理</h1>
                        </div>
                    </div>
                </div>
            </div>
            <h5></h5>
            <table id="demo" lay-filter="test"></table>
            <br><br>

            </div>
        </div>
    </div>
</div>
<!--搜索-->
<div id="search">
    <button type="button" class="close">×</button>
    <form>
        <input type="search" value="" placeholder="type keyword(s) here" />
        <button type="submit" class="btn btn-primary">Search</button>
    </form>
</div>
<script type="text/html" id="barDemo">
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
</script>

<script src="../frame/assets/js/lib/jquery.min.js"></script>
<script src="../frame/assets/js/lib/jquery.nanoscroller.min.js"></script>
<script src="../frame/assets/js/lib/menubar/sidebar.js"></script>
<script src="../frame/assets/js/lib/bootstrap.min.js"></script>
<script src="../frame/assets/js/lib/data-table2/datatables.min.js"></script>
<script src="../frame/assets/js/lib/data-table2/dataTables.buttons.min.js"></script>
<script src="../frame/assets/js/lib/data-table2/buttons.flash.min.js"></script>
<script src="../frame/assets/js/lib/data-table2/jszip.min.js"></script>
<script src="../frame/assets/js/lib/data-table2/pdfmake.min.js"></script>
<script src="../frame/assets/js/lib/data-table2/vfs_fonts.js"></script>
<script src="../frame/assets/js/lib/data-table2/buttons.html5.min.js"></script>
<script src="../frame/assets/js/lib/data-table2/buttons.print.min.js"></script>
<script src="../frame/assets/js/lib/data-table2/datatables-init2.js"></script>
<script src="../frame/assets/js/lib/sweetalert/sweetalert.min.js"></script>
<script src="../frame/assets/js/lib/sweetalert/zhuxiao.js"></script>
<script type="text/javascript" src="../frame/layui/layui.js" charset="utf-8"></script>
<script>
    layui.use('table', function(){
        var table = layui.table
    ,util = layui.util;
        //第一个实例
        table.render({
            elem: '#demo'
            ,height: '450px'
            ,url: 'http://localhost:8080/product'//数据接口
            ,method:'get'
            ,page: true //开启分页
            ,cols: [[ //表头
                {field:'id', width:90, title: 'ID编号', sort: true,fixed:'left'}
                ,{field:'zcid', width:130, title: '资产编码',sort:true, edit: 'text'}
                ,{field:'zcname', width:130, title: '资产名称', edit: 'text'}
                ,{field:'money', width:130, title: '资产金额(元)',sort:true, edit: 'text'}
                ,{field:'zcclass', width:150, title: '资产大类', edit: 'text'}
                ,{field:'zcperson', width:120, title: '审核人', edit: 'text'}
                ,{field:'zczt', width:120, title: '资产状态', edit: 'text'}
                ,{field:'begint',width:120, title: '购置日期', sort: true, edit: 'text'}
                ,{field:'right', width:120, title: '操作',toolbar:'#barDemo'}
            ]]

        });
        table.on('edit(test)', function(obj){
            var value = obj.value //得到修改后的值
                ,data = obj.data //得到所在行所有键值
                ,field = obj.field; //得到字段
            $.ajax({
                url:"/update",
                data:JSON.stringify(obj.data),
                dataType:"json",
                contentType:"application/json",
                type:"post",
                success:function(res){
                    layer.msg("编辑成功");
                },
                error:function(res){
                    layer.msg("编辑失败！");
                }
            });
        });
        table.on('tool(test)', function(obj){
            var data = obj.data;var id=data.id;var zcid=data.zcid;
            if(obj.event === 'del'){
                layer.confirm('真的删除行么', function(index){
                    var aa = "http://localhost:8080/product1/"+obj.data.id;
                    console.log(obj.data.id);
                    $.ajax({
                        url: aa,
                        type: "POST",
                        data:{"id":obj.data.id},
                        dataType: "json",
                    });
                    obj.del();
                    //关闭弹框
                    layer.close(index);
                    layer.msg("删除成功", {icon: 6});
                });
            }

                //监听单元格编辑
            });


    });

</script>
</body>
</html>